package com.servlet.meeting;

import com.domain.MeetingRecord;
import com.fasterxml.jackson.databind.util.BeanUtil;
import com.service.MeetingService;
import com.service.impl.MettingServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

@WebServlet("/meetingAddServlet")
public class MeetingAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        MeetingRecord meetingRecord = new MeetingRecord();
        try {
            BeanUtils.populate(meetingRecord, request.getParameterMap());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        MeetingService service = new MettingServiceImpl();
        System.out.println(meetingRecord.toString());
        if (service.save(meetingRecord)) {
            response.getWriter().write("{\"status\":0,\"message\":\"ok\"}");
        }else{
            response.getWriter().write("{\"status\":1,\"message\":\"no\"}");
        }
    }
}
